package com.ruoyi.web.controller.record;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.record.domain.WordHearRecord;
import com.ruoyi.record.service.IWordHearRecordService;
import com.ruoyi.record.service.impl.WordRecordCommonService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单词听力记录Controller
 *
 * @author ruoyi
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/record/wordHear")
public class WordHearRecordController extends BaseController
{
    @Autowired
    private IWordHearRecordService wordHearRecordService;

    @Autowired
    private WordRecordCommonService recordCommonService;


    /**
     * 查询单词听力记录列表
     */
//    @PreAuthorize("@ss.hasPermi('record:wordHear:list')")
    @GetMapping("/list")
    public TableDataInfo list(WordHearRecord wordHearRecord)
    {
        WordHearRecord record = recordCommonService.selectList(wordHearRecord);
        startPage();
        List<WordHearRecord> list = wordHearRecordService.selectWordHearRecordList(record);
        return getDataTable(list);
    }

    @GetMapping("/listScene")
    public TableDataInfo listScene(WordHearRecord wordHearRecord)
    {
        WordHearRecord record = recordCommonService.selectList(wordHearRecord);
        startPage();
        List<WordHearRecord> list = wordHearRecordService.selectSceneRecordList(record);
        return getDataTable(list);
    }

    /**
     * 导出单词听力记录列表
     */
//    @PreAuthorize("@ss.hasPermi('record:wordHear:export')")
    @Log(title = "单词听力记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WordHearRecord wordHearRecord)
    {
        List<WordHearRecord> list = wordHearRecordService.selectWordHearRecordList(wordHearRecord);
        ExcelUtil<WordHearRecord> util = new ExcelUtil<WordHearRecord>(WordHearRecord.class);
        util.exportExcel(response, list, "单词听力记录数据");
    }

    /**
     * 获取单词听力记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('record:wordHear:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(wordHearRecordService.selectWordHearRecordById(id));
    }

    /**
     * 新增单词听力记录
     */
//    @PreAuthorize("@ss.hasPermi('record:wordHear:add')")
    @Log(title = "单词听力记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WordHearRecord wordHearRecord)
    {
        return toAjax(wordHearRecordService.insertWordHearRecord(wordHearRecord));
    }

    /**
     * 修改单词听力记录
     */
//    @PreAuthorize("@ss.hasPermi('record:wordHear:edit')")
    @Log(title = "单词听力记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WordHearRecord wordHearRecord)
    {
        return toAjax(wordHearRecordService.updateWordHearRecord(wordHearRecord));
    }

    /**
     * 删除单词听力记录
     */
//    @PreAuthorize("@ss.hasPermi('record:wordHear:remove')")
    @Log(title = "单词听力记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(wordHearRecordService.deleteWordHearRecordByIds(ids));
    }
}
